<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">
        <ui:define name="title">
            <h:outputText value="View Sales Order # #{salesOrderEntityController.selected.id}"></h:outputText>
        </ui:define>
        <ui:define name="content">
            <h:form prependId="false" rendered="#{loginBacking.viewSalesOrder}">
                <p:panel header="Sales Order Status:">
                    <h:panelGrid columns="11" >
                        <p:commandButton styleClass="ui-state-hover" value="Credit Check" image="ui-icon ui-icon-star" rendered="#{salesOrderEntityController.selected.activeIndex==0}"/>
                        <p:commandButton disabled="true" value="Credit Check" rendered="#{salesOrderEntityController.selected.activeIndex!=0}"/>

                        <p:separator style="width: 40px"/>

                        <p:commandButton styleClass="ui-state-hover" value="Inventory Sourcing" image="ui-icon ui-icon-star" rendered="#{salesOrderEntityController.selected.activeIndex==1}"/>
                        <p:commandButton disabled="true" value="Inventory Sourcing" rendered="#{salesOrderEntityController.selected.activeIndex!=1}"/>

                        <p:separator style="width: 40px"/>

                        <p:commandButton styleClass="ui-state-hover" value="Confirmation" image="ui-icon ui-icon-star" rendered="#{salesOrderEntityController.selected.activeIndex==2}"/>
                        <p:commandButton disabled="true" value="Confirmation" rendered="#{salesOrderEntityController.selected.activeIndex!=2}"/>

                        <p:separator style="width: 40px"/>

                        <p:commandButton styleClass="ui-state-hover" value="Delivery" image="ui-icon ui-icon-star" rendered="#{salesOrderEntityController.selected.activeIndex==3}"/>
                        <p:commandButton disabled="true" value="Delivery" rendered="#{salesOrderEntityController.selected.activeIndex!=3}"/>

                        <p:separator style="width: 40px"/>

                        <p:commandButton styleClass="ui-state-hover" value="Payment" image="ui-icon ui-icon-star" rendered="#{salesOrderEntityController.selected.activeIndex==4}"/>
                        <p:commandButton disabled="true" value="Payment" rendered="#{salesOrderEntityController.selected.activeIndex!=4}"/>

                        <p:separator style="width: 40px"/>

                        <p:commandButton styleClass="ui-state-hover" value="Completed" image="ui-icon ui-icon-star" rendered="#{salesOrderEntityController.selected.activeIndex==5}"/>
                        <p:commandButton disabled="true" value="Completed" rendered="#{salesOrderEntityController.selected.activeIndex!=5}"/>
                    </h:panelGrid>
                </p:panel>
                <p:tabView effect="opacity" effectDuration="normal" dynamic="false" cache="true"> 

                    <p:messages />
                    <br />
                    <p:tab title="Sales Order Detail" >                       
                        <ui:include src="/entities/salesOrderEntity/ViewSO.xhtml" />
                        <ui:include src="/entities/salesOrderEntity/ViewMetaInfo.xhtml" />
                    </p:tab>
                    <p:tab title="Purchase Order" >              
                        <ui:include src="/entities/purchaseOrderEntity/ViewToBeIncluded.xhtml" />
                    </p:tab>
                    <p:tab title="Shipping Information" > 
                        <ui:include src="/entities/shippingRequestEntity/ListShippingRequests.xhtml" />
                        <ui:include src="/entities/shippingOrderEntity/ListForSOForInclude.xhtml" />
                    </p:tab>
                    <p:tab title="Credit Payment" > 
                        <ui:include src="/entities/salesOrderEntity/ViewCreditPayment.xhtml" />
                        <ui:include src="/entities/billingRequestEntity/ListToBeIncluded.xhtml" />
                    </p:tab>                                        

                </p:tabView>
                <br />
                <h:panelGrid columns="3">
                    <p:menuButton value="Employees Actions"> 
                        <p:menuitem ajax="false" icon="ui-icon ui-icon-trash" action="#{salesOrderEntityController.destroyAndView}" value="Delete" rendered="#{loginBacking.deleteSalesOrder}"/>
                    </p:menuButton>

                    <p:menuButton value="Inventory" rendered="#{salesOrderEntityController.inventoryMenu()}"> 
                        <p:menuitem update="checkInventory" oncomplete="checkInventoryDialog.show()" value="Check Inventory Stock">
                            <f:setPropertyActionListener value="#{salesOrderEntityController.selected.purchaseOrder.productQuantityPrice}"   
                                                         target="#{completedGoodsEntityController.pqp}" />

                                <f:setPropertyActionListener value ="#{salesOrderEntityController.selected}" target="#{salesOrderEntityController.current}"/>
                            </p:menuitem>
                            <p:menuitem action="#{masterProductionScheduleMonthlyEntityController.prepareListNoRedirect}" update="checkPlannedProduction, selectPlannedProductionPanel" id="plannedProductionCheck" oncomplete="selectPlannedProductionDialog.show()" value="Check planned production stocks">
                                <f:setPropertyActionListener value="#{salesOrderEntityController.selected.purchaseOrder.productQuantityPrice}"   
                                                             target="#{completedGoodsEntityController.pqp}" /> 
                                <f:setPropertyActionListener value ="#{salesOrderEntityController.selected}" target="#{salesOrderEntityController.current}"/>
                            </p:menuitem>
                            <p:menuitem oncomplete="unreserveDialog.show()" update="unreserveDataTable" action="#{reservationEntityController.showReservations}" value="Unreserve stocks">
                                <f:setPropertyActionListener value ="#{salesOrderEntityController.selected}" 
                                                             target="#{salesOrderEntityController.current}"/>
                            </p:menuitem>
                            </p:menuButton>

                    <p:commandButton ajax="false" action="#{salesOrderEntityController.generateShippingOrders}" 
                                     value="Generate Shipping Orders" 
                                     disabled="#{!salesOrderEntityController.canRegenerateShippingOrders()}"
                                     rendered="#{salesOrderEntityController.generateShippingOrderButton()}"/>
                    <p:commandButton action="#{salesOrderEntityController.performCreditCheck}" 
                                     value="Credit Check"
                                     update="creditDisplay" 
                                     oncomplete="creditDialog.show();"
                                     rendered="#{salesOrderEntityController.needToPerformCreditCheck()}"/>
                    <p:commandButton ajax="false" action="/entities/shippingOrderEntity/ListForSO.xhtml" 
                                     value="Request for Billing" 
                                     rendered="#{salesOrderEntityController.requestForBillingButton()}">
                        <f:setPropertyActionListener target="#{purchaseOrderEntityController.current}" value="#{current.purchaseOrder}" />
                    </p:commandButton>

                </h:panelGrid>

                <br /> 

                <p:dialog id="unreserveDialogId" header="List of reservations for sales order ##{salesOrderEntityController.selected.id}" widgetVar="unreserveDialog" width="1000" height="600" modal="true">     
                    <p:panel id="panel">
                        <p:dataTable id="unreserveDataTable" value="#{reservationEntityController.soReservations}" var="reservation" >  
                            <p:column headerText="Reservation #">

                                <h:outputLabel for="reservationID" value="#{reservation.id}" /> 
                            </p:column>

                            <p:column headerText="Product Name" >

                                <h:outputLabel for="productName" value="#{reservation.product.productName}" /> 
                            </p:column> 

                            <p:column headerText="Quantity" >
                                <h:outputLabel for="quantity" value="#{reservation.quantity}" />       
                            </p:column>
                            <p:column>
                                <h:outputLabel for="quantity" value="#{reservation.quantity}" />       
                            </p:column>
                            <p:column>

                                <p:commandButton update="panel, unreserveDataTable" action="#{reservationEntityController.unreserve}" value="Unreserve">
                                    <f:setPropertyActionListener target="#{reservationEntityController.current}" value="#{reservation}"/> 
                                </p:commandButton>

                            </p:column>
                        </p:dataTable> 
                    </p:panel>

                    <p:panel toggleable="true" id="plannedReserveList" header="Planned Reservations">
                        <p:dataTable value="#{plannedReserveEntityController.items}" 
                                     var="item"  
                                     style="table-layout:fixed" paginator="true" rows="10"  
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                     rowsPerPageTemplate="5,10,15">  
                            <p:column filterBy="#{item.id}">
                                <f:facet name="header">
                                    <h:outputText value="Planned Reservation #"/>
                                </f:facet>
                                <h:outputText value="#{item.id}"/>
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Sales Order #"/>
                                </f:facet>
                                <h:outputText value="#{item.salesOrder.id}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Fulfilment Date"/>
                                </f:facet>
                                <h:outputText value="#{item.monthOfProduction}/#{item.yearOfProduction}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Product Name"/>
                                </f:facet>
                                <h:outputText value="#{item.product.productName}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Quantity"/>
                                </f:facet>
                                <h:outputText value="#{item.quantity}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Amount Fulfilled"/>
                                </f:facet>
                                <h:outputText value="#{item.amountFulfilled}"/>
                            </p:column>
                            <p:column>
                                <p:commandButton update="plannedReserveList" action="#{reservationEntityController.unreservePlanned}" value="Unreserve">
                                    <f:setPropertyActionListener target="#{reservationEntityController.current}" value="#{item}"/> 
                                </p:commandButton>
                            </p:column>

                        </p:dataTable>
                    </p:panel>
                </p:dialog>



                <p:dialog header="Inventory Stock Check" widgetVar="checkInventoryDialog" width="800" height="400" modal="true">  

                    <p:outputPanel id="checkInventory" style="text-align:center;" layout="block">  
                        <h:panelGrid id="panelGrid" border="2"  columns="7" cellpadding="5">  
                            <h:outputLabel value=" " />
                            <h:outputLabel value="Required" /> 
                            <h:outputLabel value="Available" />
                            <h:outputLabel value="Currently Reserved"/>
                            <h:outputLabel value="Quantity Reserved"/>
                            <h:outputLabel value=" " />
                            <h:outputLabel value=" " />

                            <h:outputLabel for="ClassicNutriBarNuts" value="Classic Nutri Bar (Nuts): " />  
                            <h:outputText id="ClassicNutriBarNuts" value="#{completedGoodsEntityController.classicNutriBarNuts}" />
                            <h:outputText id="totalClassicNutriBarNuts" value="#{completedGoodsEntityController.totalClassicNutriBarNuts}" />
                            <h:outputText id="reservedClassicNutriBarNuts" value="#{salesOrderEntityController.reservedNutriBarNuts}" />
                            <h:outputText style="color: #6CE26C" value="Sufficient" rendered ="#{completedGoodsEntityController.classicNutriBarNuts le completedGoodsEntityController.totalClassicNutriBarNuts and salesOrderEntityController.reservedNutriBarNuts eq 0}" />
                            <h:outputText  style="color: #D20005" value="Insufficient" rendered ="#{completedGoodsEntityController.classicNutriBarNuts gt completedGoodsEntityController.totalClassicNutriBarNuts and salesOrderEntityController.reservedNutriBarNuts eq 0} "  />
                            <h:outputText style="color: #6CE26C" value="Reserved" 
                                          rendered ="#{salesOrderEntityController.reservedNutriBarNuts gt 0}" />

                            <p:inputText id="input1" value="#{reservationEntityController.reservePdtQuantity}"/>
                            <p:commandButton process="@this, input1" update="reservedClassicNutriBarNuts, totalClassicNutriBarNuts, panelGrid" 
                                             disabled="#{completedGoodsEntityController.classicNutriBarNuts le salesOrderEntityController.reservedNutriBarNuts or completedGoodsEntityController.totalClassicNutriBarNuts==0}" 
                                             action="#{reservationEntityController.reserveCG}" value="Reserve">
                                <f:setPropertyActionListener target="#{reservationEntityController.reservePdtName}" value="Classic Nutri Bar (Nuts)"/> 

                            </p:commandButton>

                            <h:outputLabel for="ClassicNutriBarFruits" value="Classic Nutri Bar (Fruits): " />  
                            <h:outputText id="ClassicNutriBarFruits" value="#{completedGoodsEntityController.classicNutriBarFruits}" />  
                            <h:outputText id="totalClassicNutriBarFruits" value="#{completedGoodsEntityController.totalClassicNutriBarFruits}" />
                            <h:outputText id="reservedClassicNutriBarFruits" value="#{salesOrderEntityController.reservedNutriBarFruits}" />
                            <h:outputText style="color: #6CE26C" value="Sufficient" rendered ="#{completedGoodsEntityController.classicNutriBarFruits le completedGoodsEntityController.totalClassicNutriBarFruits and salesOrderEntityController.reservedNutriBarFruits eq 0}" />
                            <h:outputText  style="color: #D20005" value="Insufficient" rendered ="#{completedGoodsEntityController.classicNutriBarFruits gt completedGoodsEntityController.totalClassicNutriBarFruits and salesOrderEntityController.reservedNutriBarFruits eq 0}" />
                            <h:outputText style="color: #6CE26C" value="Reserved" 
                                          rendered ="#{salesOrderEntityController.reservedNutriBarFruits gt 0}" />

                            <p:inputText id="input2" value="#{reservationEntityController.reservePdtQuantity}"/>
                            <p:commandButton process="@this, input2" update="reservedClassicNutriBarFruits, totalClassicNutriBarFruits, panelGrid" 
                                             disabled="#{completedGoodsEntityController.classicNutriBarFruits le salesOrderEntityController.reservedNutriBarFruits or completedGoodsEntityController.totalClassicNutriBarFruits==0}" 
                                             action="#{reservationEntityController.reserveCG}" value="Reserve">
                                <f:setPropertyActionListener target="#{reservationEntityController.reservePdtName}" value="Classic Nutri Bar (Fruits)"/> 

                            </p:commandButton>

                            <h:outputLabel for="PremiumPowerBarNuts" value="Premium Power Bar (Chocolate Nuts): " />  
                            <h:outputText id="PremiumPowerBarNuts" value="#{completedGoodsEntityController.premiumPowerBarNuts}" />  
                            <h:outputText id="totalPremiumPowerBarNuts" value="#{completedGoodsEntityController.totalPremiumPowerBarNuts}" />
                            <h:outputText id="reservedPremiumPowerBarNuts" value="#{salesOrderEntityController.reservedPremiumPowerBarNuts}" />
                            <h:outputText style="color: #6CE26C" value="Sufficient" rendered ="#{completedGoodsEntityController.premiumPowerBarNuts le completedGoodsEntityController.totalPremiumPowerBarNuts and salesOrderEntityController.reservedPremiumPowerBarNuts eq 0}" />
                            <h:outputText style="color: #D20005" value="Insufficient" rendered ="#{completedGoodsEntityController.premiumPowerBarNuts gt completedGoodsEntityController.totalPremiumPowerBarNuts and salesOrderEntityController.reservedPremiumPowerBarNuts eq 0}" />
                            <h:outputText style="color: #6CE26C" value="Reserved" 
                                          rendered ="#{salesOrderEntityController.reservedPremiumPowerBarNuts gt 0}" />

                            <p:inputText id="input3" value="#{reservationEntityController.reservePdtQuantity}"/>
                            <p:commandButton process="@this, input3" update="reservedPremiumPowerBarNuts, totalPremiumPowerBarNuts, panelGrid" 
                                             disabled="#{completedGoodsEntityController.premiumPowerBarNuts le salesOrderEntityController.reservedPremiumPowerBarNuts or completedGoodsEntityController.totalPremiumPowerBarNuts==0}" 
                                             action="#{reservationEntityController.reserveCG}" value="Reserve">
                                <f:setPropertyActionListener target="#{reservationEntityController.reservePdtName}" value="Premium Power Bar (Chocolate Nuts)"/> 

                            </p:commandButton>

                            <h:outputLabel for="PremiumPowerBarFruits" value="Premium Power Bar (Redcurrant Fruits): " />  
                            <h:outputText id="PremiumPowerBarFruits" value="#{completedGoodsEntityController.premiumPowerBarFruits}" />  
                            <h:outputText id="totalPremiumPowerBarFruits" value="#{completedGoodsEntityController.totalPremiumPowerBarFruits}" />
                            <h:outputText id="reservedPremiumPowerBarFruits" value="#{salesOrderEntityController.reservedPremiumPowerBarFruits}" />
                            <h:outputText style="color: #6CE26C" value="Sufficient" rendered ="#{completedGoodsEntityController.premiumPowerBarFruits le completedGoodsEntityController.totalPremiumPowerBarFruits and salesOrderEntityController.reservedPremiumPowerBarFruits eq 0}" />
                            <h:outputText style="color: #D20005" value="Insufficient" rendered ="#{completedGoodsEntityController.premiumPowerBarFruits gt completedGoodsEntityController.totalPremiumPowerBarFruits and salesOrderEntityController.reservedPremiumPowerBarFruits eq 0}" />
                            <h:outputText style="color: #6CE26C" value="Reserved" 
                                          rendered ="#{salesOrderEntityController.reservedPremiumPowerBarFruits gt 0}" />

                            <p:inputText id="input4" value="#{reservationEntityController.reservePdtQuantity}"/>
                            <p:commandButton process="@this, input4" update="reservedPremiumPowerBarFruits, totalPremiumPowerBarFruits, checkInventory" 
                                             disabled="#{completedGoodsEntityController.premiumPowerBarFruits le salesOrderEntityController.reservedPremiumPowerBarFruits or completedGoodsEntityController.totalPremiumPowerBarFruits==0}" action="#{reservationEntityController.reserveCG}" value="Reserve">
                                <f:setPropertyActionListener target="#{reservationEntityController.reservePdtName}" value="Premium Power Bar (Redcurrant Fruits)"/> 

                            </p:commandButton>

                        </h:panelGrid> 
                    </p:outputPanel>
                </p:dialog>

                <p:dialog header="Credit Check" widgetVar="creditDialog" closable="false" width="600">  
                    <h:panelGrid id="creditDisplay" columns="2" >
                        <h:outputText value="Credit Check #{salesOrderEntityController.selected.creditCheckStatus}" style="#{salesOrderEntityController.style}"/>
                        <h:outputText value=" " />

                        <h:outputLabel value="Credit Payable: " />
                        <h:outputText value="#{salesOrderEntityController.selected.creditPayable}" />

                        <h:outputLabel value="Cash Payable: " />
                        <h:outputText value="#{salesOrderEntityController.selected.cashPayable}" />

                        <p:commandButton value="Proceed" 
                                         onclick="creditDialog.hide();"
                                         update="@form"
                                         rendered="#{salesOrderEntityController.selected.creditCheckPassed}"/>
                        <h:outputText value=" " rendered="#{salesOrderEntityController.selected.creditCheckPassed}"/>

                        <h:commandLink value="Request for Cash-In-Advance Billing" 
                                       action="#{salesOrderEntityController.generateBillingRequestForCIA}"
                                       rendered="#{!salesOrderEntityController.selected.creditCheckPassed}"/>
                        <h:commandLink value="Amend Sales Order" 
                                       actionListener="#{salesOrderEntityController.undoCreditCheck}"
                                       action="#{purchaseOrderEntityController.prepareEditFromView}" 
                                       rendered="#{!salesOrderEntityController.selected.creditCheckPassed}"/>
                    </h:panelGrid>
                </p:dialog>


                <p:dialog closeListener="#{reservationEntityController.refreshPage}" header="Planned Production Select" widgetVar="selectPlannedProductionDialog" width="1000" height="400" modal="true">
                    <p:panel id="selectPlannedProductionPanel" header="#{bundle.ListMasterProductionScheduleMonthlyEntityTitle}">
                        <h:panelGroup rendered="#{masterProductionScheduleMonthlyEntityController.items.rowCount > 0}">
                            <p:dataTable value="#{masterProductionScheduleMonthlyEntityController.items}" 
                                         var="item" style="table-layout:fixed"
                                         paginator="true" rows="10"  
                                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                         rowsPerPageTemplate="5,10,15">
                                <p:column filterBy="#{item.type}">
                                    <f:facet name="header">
                                        <h:outputText value="Period"/>
                                    </f:facet>
                                    <h:outputText value="#{item.type}"/>
                                </p:column>
                                <p:column filterBy="#{item.yearOfProduction}">
                                    <f:facet name="header">
                                        <h:outputText value="Year"/>
                                    </f:facet>
                                    <h:outputText value="#{item.yearOfProduction}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="&nbsp;"/>
                                    </f:facet>
                                    <p:commandButton oncomplete="checkPlannedProductionDialog.show()" value="Select" action="#{masterProductionScheduleMonthlyEntityController.prepareViewNoRedirect}"/>
                                </p:column>
                            </p:dataTable>
                        </h:panelGroup>
                    </p:panel>
                </p:dialog>


                <p:dialog closeListener="#{reservationEntityController.refreshPage}" header="Planned Production Check for #{masterProductionScheduleMonthlyEntityController.selected.type} of #{masterProductionScheduleMonthlyEntityController.selected.yearOfProduction}" widgetVar="checkPlannedProductionDialog" width="1000" height="400" modal="true">
                    <p:outputPanel id="checkPlannedProduction" style="text-align:center;" layout="block">  
                        <h:panelGrid id="panelGrid1" border="2"  columns="4" cellpadding="5">  
                            <h:outputLabel value=" " />
                            <h:outputLabel value="Required" /> 
                            <h:outputLabel value="Currently Reserved"/>
                            <h:outputLabel value=" " />


                            <h:outputLabel for="ClassicNutriBarNuts" value="Classic Nutri Bar (Nuts): " />  
                            <h:outputText id="ClassicNutriBarNuts1" value="#{completedGoodsEntityController.classicNutriBarNuts}" />
                            <h:outputText id="reservedClassicNutriBarNuts1" value="#{salesOrderEntityController.reservedNutriBarNuts}" />
                            <h:outputText style="color: #6CE26C" value="Sufficient" rendered ="#{completedGoodsEntityController.classicNutriBarNuts le completedGoodsEntityController.totalClassicNutriBarNuts and salesOrderEntityController.reservedNutriBarNuts eq 0}" />
                            <h:outputText  style="color: #D20005" value="Insufficient" rendered ="#{completedGoodsEntityController.classicNutriBarNuts gt completedGoodsEntityController.totalClassicNutriBarNuts and salesOrderEntityController.reservedNutriBarNuts eq 0} "  />
                            <h:outputText style="color: #6CE26C" value="Reserved" 
                                          rendered ="#{salesOrderEntityController.reservedNutriBarNuts gt 0}" />

                            <h:outputLabel for="ClassicNutriBarFruits" value="Classic Nutri Bar (Fruits): " />  
                            <h:outputText id="ClassicNutriBarFruits1" value="#{completedGoodsEntityController.classicNutriBarFruits}" />  
                            <h:outputText id="reservedClassicNutriBarFruits1" value="#{salesOrderEntityController.reservedNutriBarFruits}" />
                            <h:outputText style="color: #6CE26C" value="Sufficient" rendered ="#{completedGoodsEntityController.classicNutriBarFruits le completedGoodsEntityController.totalClassicNutriBarFruits and salesOrderEntityController.reservedNutriBarFruits eq 0}" />
                            <h:outputText  style="color: #D20005" value="Insufficient" rendered ="#{completedGoodsEntityController.classicNutriBarFruits gt completedGoodsEntityController.totalClassicNutriBarFruits and salesOrderEntityController.reservedNutriBarFruits eq 0}" />
                            <h:outputText style="color: #6CE26C" value="Reserved" 
                                          rendered ="#{salesOrderEntityController.reservedNutriBarFruits gt 0}" />


                            <h:outputLabel for="PremiumPowerBarNuts" value="Premium Power Bar (Chocolate Nuts): " />  
                            <h:outputText id="PremiumPowerBarNuts1" value="#{completedGoodsEntityController.premiumPowerBarNuts}" />  
                            <h:outputText id="reservedPremiumPowerBarNuts1" value="#{salesOrderEntityController.reservedPremiumPowerBarNuts}" />
                            <h:outputText style="color: #6CE26C" value="Sufficient" rendered ="#{completedGoodsEntityController.premiumPowerBarNuts le completedGoodsEntityController.totalPremiumPowerBarNuts and salesOrderEntityController.reservedPremiumPowerBarNuts eq 0}" />
                            <h:outputText style="color: #D20005" value="Insufficient" rendered ="#{completedGoodsEntityController.premiumPowerBarNuts gt completedGoodsEntityController.totalPremiumPowerBarNuts and salesOrderEntityController.reservedPremiumPowerBarNuts eq 0}" />
                            <h:outputText style="color: #6CE26C" value="Reserved" 
                                          rendered ="#{salesOrderEntityController.reservedPremiumPowerBarNuts gt 0}" />

                            <h:outputLabel for="PremiumPowerBarFruits" value="Premium Power Bar (Redcurrant Fruits): " />  
                            <h:outputText id="PremiumPowerBarFruits1" value="#{completedGoodsEntityController.premiumPowerBarFruits}" />  
                            <h:outputText id="reservedPremiumPowerBarFruits1" value="#{salesOrderEntityController.reservedPremiumPowerBarFruits}" />
                            <h:outputText style="color: #6CE26C" value="Sufficient" rendered ="#{completedGoodsEntityController.premiumPowerBarFruits le completedGoodsEntityController.totalPremiumPowerBarFruits and salesOrderEntityController.reservedPremiumPowerBarFruits eq 0}" />
                            <h:outputText style="color: #D20005" value="Insufficient" rendered ="#{completedGoodsEntityController.premiumPowerBarFruits gt completedGoodsEntityController.totalPremiumPowerBarFruits and salesOrderEntityController.reservedPremiumPowerBarFruits eq 0}" />
                            <h:outputText style="color: #6CE26C" value="Reserved" 
                                          rendered ="#{salesOrderEntityController.reservedPremiumPowerBarFruits gt 0}" />
                        </h:panelGrid> 
                    </p:outputPanel>


                    <p:fieldset legend="Production Line 1" toggleable="true" toggleSpeed="500" collapsed="false">
                        <p:dataTable id="sopDataTable1" value="#{masterProductionScheduleMonthlyEntityController.createItems}" 
                                     var="item" style="table-layout:fixed"
                                     rows="6" binding="#{masterProductionScheduleMonthlyEntityController.dataTable}">

                            <p:column headerText="Month Of Production" >
                                <h:outputText value="#{item.monthOfProduction}"/>
                            </p:column>

                            <p:column headerText="View Details">
                                <p:rowToggler/>
                            </p:column>


                            <p:rowExpansion>
                                <p:panel id="rowExpansionId1">
                                    <h:panelGrid border="2" columns="4">
                                        <h:outputLabel value="Product Name"/>
                                        <h:outputLabel value="Planned Quantity"/>
                                        <h:outputLabel value="Quantity Reserved"/>
                                        <h:outputLabel value=""/>

                                        <h:outputLabel value="Classic Nutri Bar (Nuts)"/>
                                        <h:outputText value="#{item.classicNuts}" style="width:80px"/>
                                        <h:outputText   value="#{item.reservedClassicNuts}/#{item.classicNuts}" style="color:#6CE26C;width:80px"/>
                                        <p:inputText value="#{reservationEntityController.plannedReserveQuantity}">
                                            <p:commandButton disabled="#{item.classicNuts==0 or item.reservedClassicNuts ge item.classicNuts}" update="plannedReserveList, rowExpansionId1, panelGrid1" value="Reserve" action="#{reservationEntityController.plannedReserveCG}">
                                                <f:setPropertyActionListener value="Classic Nutri Bar (Nuts)" target="#{reservationEntityController.reservePdtName}"/>
                                                <f:setPropertyActionListener value="#{item}" target="#{reservationEntityController.mpsMonthly}"/>
                                            </p:commandButton>
                                        </p:inputText> 

                                        <h:outputLabel value="Classic Nutri Bar (Fruits)"/>
                                        <h:outputText value="#{item.classicFruits}" style="width:80px"/>
                                        <h:outputText   value="#{item.reservedClassicFruits}/#{item.classicFruits}" style="color:#6CE26C;width:80px"/>
                                        <p:inputText value="#{reservationEntityController.plannedReserveQuantity1}">
                                            <p:commandButton disabled="#{item.classicFruits==0 or item.reservedClassicFruits ge item.classicFruits}" update="plannedReserveList, rowExpansionId1, panelGrid1" value="Reserve" action="#{reservationEntityController.plannedReserveCG}">
                                                <f:setPropertyActionListener value="Classic Nutri Bar (Fruits)" target="#{reservationEntityController.reservePdtName}"/>
                                                <f:setPropertyActionListener value="#{item}" target="#{reservationEntityController.mpsMonthly}"/>
                                            </p:commandButton>
                                        </p:inputText>

                                        <h:outputLabel value="Premium Power Bar (Chocolate Nuts)"/>
                                        <h:outputText value="#{item.premiumNuts}" style="width:80px"/>
                                        <h:outputText   value="#{item.reservedPremiumNuts}/#{item.premiumNuts}" style="color:#6CE26C;width:80px"/>
                                        <p:inputText value="#{reservationEntityController.plannedReserveQuantity2}">
                                            <p:commandButton disabled="#{item.premiumNuts==0 or item.reservedPremiumNuts ge item.premiumNuts}" update="plannedReserveList, rowExpansionId1, panelGrid1" value="Reserve" action="#{reservationEntityController.plannedReserveCG}">
                                                <f:setPropertyActionListener value="Premium Power Bar (Chocolate Nuts)" target="#{reservationEntityController.reservePdtName}"/>
                                                <f:setPropertyActionListener value="#{item}" target="#{reservationEntityController.mpsMonthly}"/>
                                            </p:commandButton>
                                        </p:inputText>

                                        <h:outputLabel value="Premium Power Bar (Redcurrant Fruits)"/>
                                        <h:outputText value="#{item.premiumFruits}" style="align:center;width:80px"/>
                                        <h:outputText   value="#{item.reservedPremiumFruits}/#{item.premiumFruits}" style="color:#6CE26C;width:80px"/>
                                        <p:inputText value="#{reservationEntityController.plannedReserveQuantity3}">
                                            <p:commandButton disabled="#{item.premiumFruits==0 or item.reservedPremiumFruits ge item.premiumFruits}" 
                                                             update="plannedReserveList, rowExpansionId1, panelGrid1" 
                                                             value="Reserve" 
                                                             action="#{reservationEntityController.plannedReserveCG}">
                                                <f:setPropertyActionListener value="Premium Power Bar (Redcurrant Fruits)" target="#{reservationEntityController.reservePdtName}"/>
                                                <f:setPropertyActionListener value="#{item}" target="#{reservationEntityController.mpsMonthly}"/>
                                            </p:commandButton>
                                        </p:inputText>

                                    </h:panelGrid>
                                </p:panel>
                            </p:rowExpansion>  

                        </p:dataTable>

                    </p:fieldset>


                    <p:fieldset legend="Production Line 2" toggleable="true" toggleSpeed="500" collapsed="false">
                        <p:dataTable id="sopDataTable2" value="#{masterProductionScheduleMonthlyEntityController.createItems2}" 
                                     var="item" style="table-layout:fixed"
                                     rows="6" binding="#{masterProductionScheduleMonthlyEntityController.dataTable2}">

                            <p:column headerText="Month Of Production" >
                                <h:outputText value="#{item.monthOfProduction}"/>
                            </p:column>

                            <p:column headerText="View Details">
                                <p:rowToggler/>
                            </p:column>


                            <p:rowExpansion>
                                <p:panel id="rowExpansionId2">
                                    <h:panelGrid border="2" columns="4">
                                        <h:outputLabel value="Product Name"/>
                                        <h:outputLabel value="Planned Quantity"/>
                                        <h:outputLabel value="Quantity Reserved"/>
                                        <h:outputLabel value=""/>

                                        <h:outputLabel value="Classic Nutri Bar (Nuts)"/>
                                        <h:outputText value="#{item.classicNuts}" style="width:80px"/>
                                        <h:outputText   value="#{item.reservedClassicNuts}/#{item.classicNuts}" style="color:#6CE26C;width:80px"/>
                                        <p:inputText value="#{reservationEntityController.plannedReserveQuantity4}">    
                                            <p:commandButton disabled="#{item.classicNuts==0 or item.reservedClassicNuts ge item.classicNuts}" update="rowExpansionId2, panelGrid1" value="Reserve" action="#{reservationEntityController.plannedReserveCG}">
                                                <f:setPropertyActionListener value="Classic Nutri Bar (Nuts)" target="#{reservationEntityController.reservePdtName}"/>
                                                <f:setPropertyActionListener value="#{item}" target="#{reservationEntityController.mpsMonthly}"/>
                                            </p:commandButton>
                                        </p:inputText> 

                                        <h:outputLabel value="Classic Nutri Bar (Fruits)"/>
                                        <h:outputText value="#{item.classicFruits}" style="width:80px"/>
                                        <h:outputText   value="#{item.reservedClassicFruits}/#{item.classicFruits}" style="color:#6CE26C;width:80px"/>
                                        <p:inputText value="#{reservationEntityController.plannedReserveQuantity5}">
                                            <p:commandButton disabled="#{item.classicFruits==0 or item.reservedClassicFruits ge item.classicFruits}" update="rowExpansionId2, panelGrid1" value="Reserve" action="#{reservationEntityController.plannedReserveCG}">
                                                <f:setPropertyActionListener value="Classic Nutri Bar (Fruits)" target="#{reservationEntityController.reservePdtName}"/>
                                                <f:setPropertyActionListener value="#{item}" target="#{reservationEntityController.mpsMonthly}"/>
                                            </p:commandButton>
                                        </p:inputText>

                                        <h:outputLabel value="Premium Power Bar (Chocolate Nuts)"/>
                                        <h:outputText value="#{item.premiumNuts}" style="width:80px"/>
                                        <h:outputText   value="#{item.reservedPremiumNuts}/#{item.premiumNuts}" style="color:#6CE26C;width:80px"/>
                                        <p:inputText value="#{reservationEntityController.plannedReserveQuantity6}">
                                            <p:commandButton disabled="#{item.premiumNuts==0 or item.reservedPremiumNuts ge item.premiumNuts}" update="rowExpansionId2, panelGrid1" value="Reserve" action="#{reservationEntityController.plannedReserveCG}">
                                                <f:setPropertyActionListener value="Premium Power Bar (Chocolate Nuts)" target="#{reservationEntityController.reservePdtName}"/>
                                                <f:setPropertyActionListener value="#{item}" target="#{reservationEntityController.mpsMonthly}"/>
                                            </p:commandButton>
                                        </p:inputText>

                                        <h:outputLabel value="Premium Power Bar (Redcurrant Fruits)"/>
                                        <h:outputText value="#{item.premiumFruits}" style="align:center;width:80px"/>
                                        <h:outputText   value="#{item.reservedPremiumFruits}/#{item.premiumFruits}" style="color:#6CE26C;width:80px"/>
                                        <p:inputText value="#{reservationEntityController.plannedReserveQuantity7}">
                                            <p:commandButton disabled="#{item.premiumFruits==0 or item.reservedPremiumFruits ge item.premiumFruits}" update="rowExpansionId2, panelGrid1" value="Reserve" action="#{reservationEntityController.plannedReserveCG}">
                                                <f:setPropertyActionListener value="Premium Power Bar (Redcurrant Fruits)" target="#{reservationEntityController.reservePdtName}"/>
                                                <f:setPropertyActionListener value="#{item}" target="#{reservationEntityController.mpsMonthly}"/>
                                            </p:commandButton>
                                        </p:inputText>

                                    </h:panelGrid>
                                </p:panel>
                            </p:rowExpansion>  
                        </p:dataTable>
                    </p:fieldset>

                </p:dialog>

                <p:confirmDialog message="Cash-in-Advance Refund available. Request for refund now?"  
                                 showEffect="bounce" hideEffect="explode"  
                                 header="Cash-in-Advance Refund" severity="alert" widgetVar="requestForRefundconfirmation">  

                    <h:outputText value="Note: " />
                    <h:inputTextarea value="#{salesOrderEntityController.note}" />

                    <p:commandButton value="Yes" update="@form" oncomplete="requestForRefundconfirmation.hide()"  
                                     actionListener="#{salesOrderEntityController.fileForCIARefundRequest}" />  
                    <p:commandButton value="Not Yet" onclick="confirmation.hide()" type="button" />   

                </p:confirmDialog> 

            </h:form>
        </ui:define>
    </ui:composition>

</html>
